package demogeric;

class Food {

}
class Fruit extends Food {

}
class Apple extends Fruit {

}
class Banana extends Fruit {

}
class Plate<T> { // 设置泛型
    private T data ;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
public class Test3 {

    public static void main(String[] args) {
        Plate<Food> plate1 = new Plate<>();
        plate1.setData(new Food());



        func2(plate1);


        //demogeric.Fruit fruit = (demogeric.Fruit)new demogeric.Food();

        /*demogeric.Food food = new demogeric.Fruit();
        demogeric.Fruit fruit = (demogeric.Fruit)food;*/


    }

    public static void func2(Plate<? super Fruit> pa) {

        //pa.setData(new demogeric.Apple());
        //pa.setData(new demogeric.Banana());

        //demogeric.Fruit fruit = (demogeric.Fruit)pa.getData();
        Object o = pa.getData();
        System.out.println(o);
    }


    public static void main1(String[] args) {
        Plate<Apple> plate1 = new Plate<>();
        plate1.setData(new Apple());

        Plate<Banana> plate2 = new Plate<>();
        plate2.setData(new Banana());

        func(plate1);
        func(plate2);

        /*demogeric.Plate<demogeric.Food> plate3 = new demogeric.Plate<>();
        func(plate3);*/
    }

    public static void func(Plate<? extends Fruit> pa) {
        //pa.setData(new demogeric.Apple());
        //pa.setData(new demogeric.Banana()); 不能知道 此时传入的是哪个子类

        Fruit fruit = pa.getData();
        System.out.println(fruit);
    }
}
